

package io.admin.common.utils;


import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExcelCopyUrils {
    public final  static String ADDRESS_FILE =ExcelUtils.ADDRESS_FILE;

    public final  static String ADDRESS_Mb_FILE ="/app/cma/download/mb/";

   public static String  copyExcel(Map<String,Object> map, String fileName,String copyFileName) throws Exception {
       FileInputStream inputStream = new FileInputStream(ADDRESS_Mb_FILE+fileName);
       XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
       // 获取工作表
       Sheet sheet = workbook.getSheetAt(0);
       for (int row = 0; row < sheet.getLastRowNum()+1; row++) {
           Row rows = sheet.getRow(row);
           if(null != rows){
               for (int col = 0; col < rows.getLastCellNum()+1; col++) {
                   Cell cell = rows.getCell(col);
                   if(null!=cell){
                       /*switch (cell.getCellType()) {
                           case STRING:
                               String key = cell.getStringCellValue();
                               System.out.println("列数" + row);
                               System.out.println("行数" + col);
                               System.out.println("值" + key);
                               if (null != map.get(key)) {
                                   cell.setCellValue((String) map.get(key));
                               }
                               break;
                           default:
                               break;
                       }*/
                   }
               }
           }
       }
       // 写入到文件
       try (FileOutputStream outputStream = new FileOutputStream(ADDRESS_FILE+copyFileName)) {
           workbook.write(outputStream);
       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           // 清理资源
           try {
               workbook.close();
           } catch (IOException e) {
               e.printStackTrace();
           }
       }
       return copyFileName;
   }
    public static void main(String[] args)throws Exception {
    }

 }
